package net.qiujuer.sample.genius.util;

import ohos.aafwk.content.Intent;
import ohos.app.Context;

public class JumpUtil {

    /**
     * 跳转Ability
     *
     * @param context
     * @param toClass
     */
    public static void jumpToAbility(Context context, Class toClass) {
        if (context == null) {
            throw new NullPointerException("you are context is null");
        }
        Intent intent = new Intent();
        intent.setOperation(new Intent.OperationBuilder()
                .withBundleName(context.getBundleName())
                .withAbilityName(toClass.getName())
                .build());
        // startAbility()方法getContext为空，所以导致直接调用startAbility内部会出错，鸿蒙的bug
        // 换成下面context调用
        context.startAbility(intent, 0);
    }

}
